var weather = {
    wea:function(){
        $(".con_left").click(function(){
            //invokeObjc("http://conlink:http://www.digitaling.com/dindex/about#enter");
            document.location = "conlink:http://www.digitaling.com/dindex/about#enter";
        });
    },

    update:function() {
        alert('-------');
    },

    clock:function(){
        (function($) {
            var _options = {};
            var _container = {};
            jQuery.fn.MyDigitClock = function(options) {
                var id = $(this).get(0).id;
                _options[id] = $.extend({}, $.fn.MyDigitClock.defaults, options);
                return this.each(function()
                {
                    _container[id] = $(this);
                    showClock(id);
                });
                function showClock(id)
                {
                    var d = new Date;
                    var h = d.getHours();
                    var m = d.getMinutes();
                    var s = d.getSeconds();
                    var ampm = "";
                    if (_options[id].bAmPm)
                    {
                        if (h>12)
                        {
                            h = h-12;
                            ampm = " PM";
                        }
                        else
                        {
                            ampm = " AM";
                        }
                    }
                    var templateStr = _options[id].timeFormat + ampm;
                    templateStr = templateStr.replace("{HH}", getDD(h));
                    templateStr = templateStr.replace("{MM}", getDD(m));
                    templateStr = templateStr.replace("{SS}", getDD(s));
                    var obj = $("#"+id);
                    obj.css("fontSize", _options[id].fontSize);
                    obj.css("fontFamily", _options[id].fontFamily);
                    obj.css("color", _options[id].fontColor);
                    obj.css("background", _options[id].background);
                    obj.css("fontWeight", _options[id].fontWeight);
                    //change reading
                    obj.html(templateStr)
                    //toggle hands
                    if (_options[id].bShowHeartBeat)
                    {
                        obj.find("#ch1").fadeTo(800, 0.1);
                        obj.find("#ch2").fadeTo(800, 0.1);
                    }
                    setTimeout(function(){showClock(id)}, 1000);
                }
                function getDD(num)
                {
                    return (num>=10)?num:"0"+num;
                }
                function refreshClock()
                {
                    setupClock();
                }
            }
//default values
            jQuery.fn.MyDigitClock.defaults = {
                fontSize: '50px',
                fontFamily: 'Microsoft JhengHei, Century gothic, Arial',
                fontColor: '#ff2200',
                fontWeight: 'bold',
                background: 'transparent',
                timeFormat: '{HH}<span id="ch1">:</span>{MM}<span id="ch2">:</span>{SS}',
                bShowHeartBeat: false,
                bAmPm:false
            };
        })(jQuery);

        $(document).ready(function(){
            $(function(){
                $("#clock1").MyDigitClock();
                $("#clock2").MyDigitClock({
                    fontSize:50,
                    fontFamily:"Century gothic",
                    fontColor: "#000",
                    fontWeight:"bold",
                    bAmPm:true,
                    background:'transparent',
                    bShowHeartBeat:true
                });

                $("#clock3").MyDigitClock({
                        fontSize:120,
                        fontColor:"grey",
                        background:"transparent",
                        fontWeight:"bold",
                        timeFormat: '{HH}:{MM}'}
                );
            });
        });
    },

    animageImg:function(){
        var images = "", count = 50;
        for(var i = 1; i <= count; i++)
            images += '<img class="grid-image" src="img/'+i+'.jpg" />';

        //appending the images to .grid
        $(".grid").append(images);
        var d = 0; //delay
        var ry, tz, s; //transform params
        function showLogin()
        {
            $("img.grid-image").each(function(){
                d = Math.random()*1000; //1ms to 1000ms delay
                $(this).delay(d).animate({opacity: 0}, {
                    //while the thumbnails are fading out, we will use the step function to apply some transforms. variable n will give the current opacity in the animation.
                    step: function(n){
                        s = 1-n; //scale - will animate from 0 to 1
                        $(this).css("transform", "scale("+s+")");
                    },
                    duration: 1000,
                })
            }).promise().done(function(){
                //after *promising* and *doing* the fadeout animation we will bring the images back
                storm();
            })
        }
        setInterval("showLogin()","10000");
        //bringing back the images with style
        function storm()
        {
            $("img.grid-image").each(function(){
                d = Math.random()*1000;
                $(this).delay(d).animate({opacity: 1}, {
                    step: function(n){
                        //rotating the images on the Y axis from 360deg to 0deg
                        ry = (1-n)*360;
                        //translating the images from 1000px to 0px
                        tz = (1-n)*1000;
                        //applying the transformation
                        $(this).css("transform", "rotateY("+ry+"deg) translateZ("+tz+"px)");
                    },
                    duration: 3000,
                    //some easing fun. Comes from the jquery easing plugin.
                    easing: 'easeOutQuint',
                })
            })
        }
    }
}


var skimImage = {
    upload:function(){
        $("#upimage").fileupload({
            url: '../weather/uploadfile',
            dataType: 'json',
            sequentialUploads: true,
            done: function(e, data) {
                if (data.result['success'] == 1) {
                    var imgStr = data.result['url'];
                    var html = "<li class='skimli'><img src='" + imgStr  + "' width='97px'></li>";
                    $(this).parent().find('#skimimage ul').append(html);
                }
            }
        });
    }
}